package com.api.gbhg.lbj.api;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liuwenbo.utils.FormatUtil;
import com.api.gbhg.lbj.dao.GeneralProjectDao;
import com.api.gbhg.lbj.tool.Tools;
import com.api.gbhg.luoao.utils.PageEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSetTrans;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lbj
 * @version 1.0
 * @description: TODO 通用项目核批列表
 * @date 2020/12/31 12:04
 */
@Path("/gbhg/generalprojec")
public class GeneralProjectApi {
    private static final Logger logger = LoggerFactory.getLogger("gbhg");

    @POST
    @Path("/getGeneralprojecData")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String getGeneralProjecData(Map<String, String> param) {
        logger.info("----测试进入进入通用项目getGeneralProjecData-----");
        String requestId = param.get("requestId");
        logger.info("通用项目-requestId--:" + requestId);
        GeneralProjectDao generalProjectDao = new GeneralProjectDao();
        RecordSetTrans rst = generalProjectDao.getGeneralProjectMainTable(requestId);
        PageEntity page = new PageEntity();
        Map<String, Object>[] map = new HashMap[rst.getArray().size()];
        int i = 0;
        while (rst.next()) {
            map[i] = new HashMap<>();
            map[i].put("lcjlsqjlid", rst.getString("lcjlsqjlid"));//requestid
            map[i].put("xmmin", rst.getString("xmmin"));//项目名称
            map[i].put("sbdw", Tools.getSBDWById(rst.getString("sbdw")));//申报单位
            map[i].put("sbks", Tools.getSBKSById(rst.getString("sbks")));//申报科室
            map[i].put("fzr", Tools.getUserNameById(rst.getString("fzr")));//负责人
            map[i].put("jbr", Tools.getUserNameById(rst.getString("jbr")));//经办人
            map[i].put("qzhgzyzbsbxq", rst.getString("qzhgzyzbsbxq"));//海关专用装备设备需求
            map[i].put("hwgz", rst.getString("zhwgz"));//货物购置
            map[i].put("xsfy", rst.getString("xsfy"));//修缮费用
            map[i].put("fwjqt", rst.getString("fwjqt"));//服务及其他
            map[i].put("zyzcnrwy", rst.getString("zyzcnrwy"));//主要经济支出(万元)
            map[i].put("je", rst.getString("je"));//政府采购预算（万元）
            map[i].put("zfcg-hwgz", rst.getString("hwgz"));//政府采购-货物购置
            map[i].put("zfcg-xecg", rst.getString("xecg"));//政府采购-小额采购
            map[i].put("zfcg-gc", rst.getString("gc"));//政府采购-工程
            map[i].put("zfcg-fw", rst.getString("fw"));//政府采购-服务
            map[i].put("fwjqt-xgfj", rst.getString("fwjqtxgfj"));//服务及其它相关附件
            map[i].put("hwgz-xgfj", rst.getString("hwgzxgfj"));//货物购置相关附件
            map[i].put("xsgc-xgfj", rst.getString("xsgcxgfj"));//修缮工程相关附件
            i++;
        }
        page.setList(map);
        page.setFromtable("uf_tyxmxzbbb");
        logger.info("通用核批map--" + map);
        return JSON.toJSONString(page);
    }

    public String getGeneralProjecData1(String requestId) {
        logger.info("----测试进入进入通用项目getGeneralProjecData-----");
//        String requestId = param.get("requestId");
        logger.info("通用项目-requestId--:" + requestId);
        GeneralProjectDao generalProjectDao = new GeneralProjectDao();
        RecordSetTrans rst = generalProjectDao.getGeneralProjectMainTable(requestId);
        PageEntity page = new PageEntity();
        Map<String, Object>[] map = new HashMap[rst.getArray().size()];
        int i = 0;
        while (rst.next()) {
            map[i] = new HashMap<>();
            BigDecimal qzhgzyzbsbxq = new BigDecimal("0.0000");
            BigDecimal hwgz = new BigDecimal("0.0000");
            BigDecimal xsfy = new BigDecimal("0.0000");
            BigDecimal fwjqt = new BigDecimal("0.0000");
            BigDecimal zyzcnrwy = new BigDecimal("0.0000");
            BigDecimal je = new BigDecimal("0.0000");
            BigDecimal zfcghwgz = new BigDecimal("0.0000");
            BigDecimal zfcgxecg = new BigDecimal("0.0000");
            BigDecimal jzfcggc = new BigDecimal("0.0000");
            BigDecimal zfcgfw = new BigDecimal("0.0000");

            qzhgzyzbsbxq = qzhgzyzbsbxq.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("qzhgzyzbsbxq"))));
            hwgz = hwgz.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("zhwgz"))));
            xsfy = xsfy.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("xsfy"))));
            fwjqt = fwjqt.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("fwjqt"))));
            zyzcnrwy = zyzcnrwy.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("zyzcnrwy"))));
            je = je.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("je"))));
            zfcghwgz = zfcghwgz.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("hwgz"))));
            zfcgxecg = zfcgxecg.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("xecg"))));
            jzfcggc = jzfcggc.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("gc"))));
            zfcgfw = zfcgfw.add(new BigDecimal(FormatUtil.DmFormat(rst.getDouble("fw"))));

            map[i].put("lcjlsqjlid", rst.getString("lcjlsqjlid"));//requestid
            map[i].put("xmmin", rst.getString("xmmin"));//项目名称
            map[i].put("sbdw", Tools.getSBDWById(rst.getString("sbdw")));//申报单位
            map[i].put("sbks", Tools.getSBKSById(rst.getString("sbks")));//申报科室
            map[i].put("fzr", Tools.getUserNameById(rst.getString("fzr")));//负责人
            map[i].put("jbr", Tools.getUserNameById(rst.getString("jbr")));//经办人
            map[i].put("qzhgzyzbsbxq", qzhgzyzbsbxq.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//海关专用装备设备需求
            map[i].put("hwgz", hwgz.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//货物购置
            map[i].put("xsfy", xsfy.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//修缮费用
            map[i].put("fwjqt", fwjqt.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//服务及其他
            map[i].put("zyzcnrwy", zyzcnrwy.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//主要经济支出(万元)
            map[i].put("je", je.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购预算（万元）
            map[i].put("zfcg-hwgz", zfcghwgz.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购-货物购置
            map[i].put("zfcg-xecg", zfcgxecg.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购-小额采购
            map[i].put("zfcg-gc", jzfcggc.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购-工程
            map[i].put("zfcg-fw", zfcgfw.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购-服务

            map[i].put("fwjqt-xgfj", rst.getString("fwjqtxgfj"));//服务及其它相关附件
            map[i].put("hwgz-xgfj", rst.getString("hwgzxgfj"));//货物购置相关附件
            map[i].put("xsgc-xgfj", rst.getString("xsgcxgfj"));//修缮工程相关附件
            i++;
        }
        page.setList(map);
        page.setFromtable("uf_tyxmxzbbb");
        logger.info("通用核批map--" + map);
        return JSON.toJSONString(page);
    }
}
